package com.fysports.web.controller.plugin;

import com.jfinal.core.Controller;
import com.fysports.framework.kit.sql.Conditions;
import com.fysports.web.model.user.BizUser;
import com.fysports.web.module.view.vo.BaseWebVO;


class SelectUserVO extends BaseWebVO {
    private String username;
    private String phone;


    public SelectUserVO(Controller ctr) {
        super(ctr);
    }


    @Override public void initParamsReq(Controller ctr) {
        this.username = decode(ctr.getPara("uname", ""));
        this.phone = ctr.getPara("uphone", "");
    }


    @Override public Conditions getConditions() {
            /* 排除UUID查询 */
        Conditions conditions = new Conditions().setExcludeField(BizUser.COL_UUID);
            /* name，phone字段查询 */
        conditions.setFiledQuery(Conditions.FUZZY, BizUser.COL_NAME, BizUser.COL_PHONE);
            /* 赋值 */
        conditions.modelToCondition(
                new BizUser().set(BizUser.COL_NAME, username).set(BizUser.COL_PHONE, phone));
        return conditions;
    }


    @Override public void setQueryData(Controller ctr) {
        super.setQueryData(ctr);
        ctr.setAttr("uname", username);
        ctr.setAttr("uphone", phone);
    }


    public String getUsername() {
        return username;
    }


    public String getPhone() {
        return phone;
    }


    @Override public String toParams() {
        return new StringBuilder("?").append("uname=").append(encode(username)).append("&").append("uphone=")
                .append(phone).toString();
    }
}
